package com.kaishengit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.ContactDao;
import com.kaishengit.pojo.Company;
import com.kaishengit.pojo.Contact;

@Service
@Transactional
public class ContactService {

	private ContactDao contactDao;
	
	
	@SuppressWarnings("unchecked")
	@Transactional(readOnly=true)
	public List<Company> findAllCompany() {
		String sql = "SELECT id,companyname,weibo,weibotype,content,`view`,createtime,address FROM t_contact WHERE companyname IS NOT NULL;";
		return contactDao.getSession().createSQLQuery(sql).addEntity(Company.class).list();
	}
	@SuppressWarnings("unchecked")
	@Transactional(readOnly=true)
	public List<Contact> findAllContacts() {
		String sql = "SELECT id,`name`,weibo,weibotype,content,`view`,createtime,address,companyid FROM t_contact WHERE `name` IS NOT NULL;";
		return contactDao.getSession().createSQLQuery(sql).addEntity(Contact.class).list();
	}
	
	
	public void saveContact(Contact contact){
		contactDao.save(contact);
	}
	
	
	//get  set
	public ContactDao getContactDao() {
		return contactDao;
	}
	@Autowired
	public void setContactDao(ContactDao contactDao) {
		this.contactDao = contactDao;
	}
	
	
	
}
